package com.museum;

import java.io.IOException;
import java.io.StringReader;
import java.net.URI;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.Vector;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xmlrpc.android.XMLRPCClient;
import org.xmlrpc.android.XMLRPCException;

import com.museum.data.Mp_Places_Items_Handler;
import com.museum.data.Mp_Places_Museum_Handler;
import com.museum.data.Mp_Places_News_Handler;
import com.museum.data.Mp_User_Bookshelf_Handler;
import com.museum.data.Mp_User_Profile_Handler;
import com.museum.data.Mp_User_Visit_Handler;
import com.museum.data.Mp_User_Watched_Handler;
import com.museum.model.Location;
import com.museum.model.Mp_Places_Items;
import com.museum.model.Mp_Places_Museum;
import com.museum.model.Mp_User_Watched;
import com.museum.model.Open_Date;
import com.museum.model.Open_Date_Item;
import com.museum.model.Place;
import com.museum.model.Visited;
import com.museum.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.support.v4.app.NavUtils;
import android.view.View.OnClickListener;

public class Mp_User_Visit_Activity extends Activity {
	TextView textviewDetail;
	
	private XMLRPCClient client;
	private URI uri;
	Visited visited;
	Place place;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mp_user_visit);
        
        bindWidget();
        setButtonEventListener();
        
        String username = "test";
        String password = "testpwd";

        String result = "";
        //##############Mp_User_Visit##################
        Mp_User_Visit_Handler a = new Mp_User_Visit_Handler(username, password);

        for(int i = 0;i < a.get_Mp_User_Visit().getVisited().getItemCount(); i++){
        	//Log.d("tag", "##place: " + a.get_Mp_User_Visit().getVisited().getItem(i).getPlaceId());
        	
        	String place_id = a.get_Mp_User_Visit().getVisited().getItem(i).getPlaceId();
          	String name = a.get_Mp_User_Visit().getVisited().getItem(i).getName();
      	    String description = a.get_Mp_User_Visit().getVisited().getItem(i).getDescription();
      	    String create_timestamp = a.get_Mp_User_Visit().getVisited().getItem(i).getCreate_Timestamp();
      	    String add_timestamp = a.get_Mp_User_Visit().getVisited().getItem(i).getAdded_Timestamp();
      	    String location_description = a.get_Mp_User_Visit().getVisited().getItem(i).getLocation().getDescription();
      	    String location_latitude = a.get_Mp_User_Visit().getVisited().getItem(i).getLocation().getLatitude();
      	    String location_longitude = a.get_Mp_User_Visit().getVisited().getItem(i).getLocation().getLongitude();
      	    String website = a.get_Mp_User_Visit().getVisited().getItem(i).getWebsite();
      	    String email = a.get_Mp_User_Visit().getVisited().getItem(i).getEmail();
      	    result += "\r\nIndex: " + i;
	      	result += "\r\nplace_id: " + place_id
	     			 +"\r\n"+ "name: "+ name
	     			 +"\r\n"+ "description: "+ description
	     			 +"\r\n"+ "create_timestamp: "+ create_timestamp
	     			 +"\r\n"+ "add_timestamp: "+ add_timestamp
	     			 +"\r\n"+ " location_description: "+ location_description
	     			 +"\r\n"+ " location_latitude: "+ location_latitude
	     			 +"\r\n"+ " location_longitude: "+ location_longitude
	     			 +"\r\n"+ "website: "+ website
	     			 +"\r\n"+ "email: "+ email;
     			 
      	    for(int j=0;j < a.get_Mp_User_Visit().getVisited().getItem(i).getOpen_Date().getItemCount();j++){
      	    	String open_date = a.get_Mp_User_Visit().getVisited().getItem(i).getOpen_Date().getItem(j).getDate();
      	    	String open_time = a.get_Mp_User_Visit().getVisited().getItem(i).getOpen_Date().getItem(j).getOpen_time();
      	    	String close_time = a.get_Mp_User_Visit().getVisited().getItem(i).getOpen_Date().getItem(j).getClose_time();
      	    	
      	    	result += "\r\n"+ " open_date: "+ open_date
			   			 +"\r\n"+ " open_time: "+ open_time
			   			 +"\r\n"+ " close_time: "+ close_time;
      	    }
      	    String status = a.get_Mp_User_Visit().getVisited().getItem(i).getStatus();
      	    String exhibition_status = a.get_Mp_User_Visit().getVisited().getItem(i).getExhibition_Status();
      	    
      	  result += "\r\n"+ "status: "+ status
		   			 +"\r\n"+ "exhibition_status: "+ exhibition_status;
        			    
        }
        
        
        for(int i = 0;i < a.get_Mp_User_Visit().getWatched().getItemCount(); i++){
        	result += "\r\n\r\nWatched:\r\n";
        	String place_id = a.get_Mp_User_Visit().getWatched().getItem(i).getPlaceId();
          	String name = a.get_Mp_User_Visit().getWatched().getItem(i).getName();
      	    String description = a.get_Mp_User_Visit().getWatched().getItem(i).getDescription();
      	    String create_timestamp = a.get_Mp_User_Visit().getWatched().getItem(i).getCreate_Timestamp();
      	    String add_timestamp = a.get_Mp_User_Visit().getWatched().getItem(i).getAdded_Timestamp();
      	    String location_description = a.get_Mp_User_Visit().getWatched().getItem(i).getLocation().getDescription();
      	    String location_latitude = a.get_Mp_User_Visit().getWatched().getItem(i).getLocation().getLatitude();
      	    String location_longitude = a.get_Mp_User_Visit().getWatched().getItem(i).getLocation().getLongitude();
      	    String website = a.get_Mp_User_Visit().getWatched().getItem(i).getWebsite();
      	    String email = a.get_Mp_User_Visit().getWatched().getItem(i).getEmail();
	      	result += "place_id: " + place_id
	     			 +"\r\n"+ "name: "+ name
	     			 +"\r\n"+ "description: "+ description
	     			 +"\r\n"+ "create_timestamp: "+ create_timestamp
	     			 +"\r\n"+ "add_timestamp: "+ add_timestamp
	     			 +"\r\n"+ " location_description: "+ location_description
	     			 +"\r\n"+ " location_latitude: "+ location_latitude
	     			 +"\r\n"+ " location_longitude: "+ location_longitude
	     			 +"\r\n"+ "website: "+ website
	     			 +"\r\n"+ "email: "+ email;
     			 
      	    for(int j=0;j < a.get_Mp_User_Visit().getWatched().getItem(i).getOpen_Date().getItemCount();j++){
      	    	String open_date = a.get_Mp_User_Visit().getWatched().getItem(i).getOpen_Date().getItem(j).getDate();
      	    	String open_time = a.get_Mp_User_Visit().getWatched().getItem(i).getOpen_Date().getItem(j).getOpen_time();
      	    	String close_time = a.get_Mp_User_Visit().getWatched().getItem(i).getOpen_Date().getItem(j).getClose_time();
      	    	
      	    	result += "\r\n"+ " open_date: "+ open_date
			   			 +"\r\n"+ " open_time: "+ open_time
			   			 +"\r\n"+ " close_time: "+ close_time;
      	    }
      	    String status = a.get_Mp_User_Visit().getWatched().getItem(i).getStatus();
      	    String exhibition_status = a.get_Mp_User_Visit().getWatched().getItem(i).getExhibition_Status();
      	    
      	  result += "\r\n"+ "status: "+ status
		   			 +"\r\n"+ "exhibition_status: "+ exhibition_status;
        }
        
        //Log.d("Visited", result);
    	textviewDetail.setText(result);
    }
    private void bindWidget(){
    	textviewDetail = (TextView)findViewById(R.id.textviewDetail);
    }
    private void setButtonEventListener(){

    }

}
